<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hello</title>
</head>
<body>

<div id="root"></div>

<script src="../lib/react.js"></script>
<script src="../lib/react-dom.js"></script>
<script src="../lib/babel-min.js"></script>

<script type="text/babel">
  class App extends React.Component {

    constructor() {
      super();                
      this.state = {
          counter: 100
      }
    }

    increment() {
      this.setState({
        counter: this.state.counter + 1
      })
    }
 
    decrement() {
      this.setState({
        counter: this.state.counter - 1
      })
    }

    render() {
      //ES6对象解构
      const { counter } = this.state;
      return (
        <div>
          <h2>当前计数:{counter}</h2>
          <button onClick={this.increment.bind(this)}>+</button>
          <button onClick={this.decrement.bind(this)}>-</button>
        </div>
      )
    }
  }

  const root = ReactDOM.createRoot(document.querySelector("#root"))
  root.render(<App/>)

</script>

</body>
</html>
